package org.rabbitmq.two;

import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import org.rabbitmq.util.RabbitMQUtil;

public class Worker01 {

    private static final String QUEUE_NAME = "hello";

    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMQUtil.getChannel();
        // 推送的消费如何进行消费的接口回调
        DeliverCallback deliverCallback = (consumerTag, message)->{
            String body = new String(message.getBody());
            System.out.println(body);
        };

        // 取消消费的回调，如在消费的时候，队列被删掉了
        CancelCallback cancelCallback = (consumerTag)->{
            System.out.println("消息消费被中断");
        };

        System.out.println("C1 消费者启动等待消费...");
        channel.basicConsume(QUEUE_NAME, true, deliverCallback,cancelCallback);
    }

}
